package org.joe.chinachess.core;

import org.joe.chinachess.core.po.Chess;
import org.joe.chinachess.utils.Constants;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ChessFactory {


    /**
     * 新建棋子，并为主要属性赋值
     *
     * @param chess
     * @param color
     * @param state
     */
    public static Chess createChess(int chess, int color, int state) {
        return Chess.builder().chess(chess).color(color).state(state).build();
    }

    /**
     * 初始化棋局开始的所有棋子
     * @return
     */
    public static List<Chess> initChesses() {
        //初始化红方棋子
        //初始化黑方棋子

        List<Chess> arrayList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            arrayList.add(createChess(1, Constants.Color.RED, Constants.Status.UNKNOW));
            arrayList.add(createChess(1, Constants.Color.BLACK, Constants.Status.UNKNOW));
        }
        for (int i = 2; i < 7; i++) {
            arrayList.add(createChess(i, Constants.Color.RED, Constants.Status.UNKNOW));
            arrayList.add(createChess(i, Constants.Color.RED, Constants.Status.UNKNOW));
            arrayList.add(createChess(i, Constants.Color.BLACK, Constants.Status.UNKNOW));
            arrayList.add(createChess(i, Constants.Color.BLACK, Constants.Status.UNKNOW));
        }
        arrayList.add(createChess(7, Constants.Color.RED, Constants.Status.UNKNOW));
        arrayList.add(createChess(7, Constants.Color.BLACK, Constants.Status.UNKNOW));
        Collections.shuffle(arrayList);
        return arrayList;
    }
}
